#include "mainwindow.h"
#include "ui_mainwindow.h"



MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    //    设置菜单栏
    //    创建菜单栏
    QMenuBar *menuBar = new QMenuBar(this);
    this->setMenuBar(menuBar); //菜单栏加入主窗体
    //    添加菜单
    QMenu *fileMenu = new QMenu("file");
    QMenu *editMenu = new QMenu("edit");
    menuBar->addMenu(fileMenu);
    menuBar->addMenu(editMenu);

    //     添加菜单内容
    QAction *newAction = new QAction(tr("new file ..."));
    QAction *openAction = new QAction(
                QIcon("img/0101_edit.png"),tr("open file..."));
    fileMenu->addAction(newAction);
    fileMenu->addAction(openAction);

    QAction *copyAction = new QAction(tr("copy"));
    copyAction->setShortcut(QKeySequence(tr("Ctrl +c")));
    QAction *pasteAction = new QAction(tr("paste"));
    editMenu->addAction(copyAction);
    editMenu->addAction(pasteAction);

    //    设置工具栏
    //创建工具栏
    QToolBar *toolBar = new QToolBar();
    //添加对齐
    this->addToolBar(toolBar);
    //    添加工具项
    toolBar->addAction(newAction);
    toolBar->addAction(openAction);
    toolBar->addAction(copyAction);
    toolBar->addAction(pasteAction);

    //    设置中心部件
    //    创建中心部件
    textEdit = new QTextEdit(tr("我是中心部件"));
    connect(textEdit,&QTextEdit::cursorPositionChanged
            ,this,&MainWindow::setStatus);

    //    添加中心部件
    this->setCentralWidget(textEdit);


    //    设置铆接部件
    QDockWidget *dockWidget = new QDockWidget(tr("铆接控件"),this);
    dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea |
                                Qt::RightDockWidgetArea);
    this->addDockWidget(Qt::LeftDockWidgetArea,dockWidget);


    //    设置状态栏
    QStatusBar *statusBar = new QStatusBar(this);
    this->setStatusBar(statusBar);

    leftLineEdit = new QLineEdit("左状态栏");
    rightLabel = new QLabel("右状态栏");
    statusBar->addWidget(leftLineEdit);//左
    statusBar->addPermanentWidget(rightLabel);//右

}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::setStatus()
{
    QTextCursor mytextCursor = textEdit->textCursor();
    QString str =   QString::number(mytextCursor.blockNumber())+
            " : "+
            QString::number( mytextCursor.columnNumber());
    rightLabel->setText(str);
}
